package com.example.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.pojo.Examine;
import com.example.pojo.PageData;
import com.example.pojo.ResultBean;
import com.example.service.IExamineService;
import com.example.vo.ExamineVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lyj
 * @since 2023-02-15
 */
@RestController
@RequestMapping("/examine")
public class ExamineController {
    @Autowired
    private IExamineService examineService;

    /**
     * 分页条件查询
     * @param pageData
     * @param map
     * @return
     */
    @GetMapping("/list")
    public ResultBean list(PageData pageData,
                           @RequestParam Map map) {
        map.forEach((k, v) -> System.out.println(k + ":" + v));

        Page<ExamineVo> page = new Page(pageData.getPageNum(), pageData.getPageSize());
        examineService.findExamineVoPage(map, page);
        return ResultBean.success(page);
    }

    /**
     * 更新或新增记录
     * @param examine
     * @return
     */
    @PostMapping("saveOrUpdate")
    public ResultBean saveOrUpdate(@RequestBody Examine examine) {
        System.out.println("新增或修改的数据：" + examine);
        boolean rs = examineService.saveOrUpdate(examine);
        return rs ? ResultBean.success() : ResultBean.error("操作失败");
    }

    /**
     * 根据ID逻辑删除记录
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    public ResultBean delete(@PathVariable("id") Long id) {
        System.out.println("要删除的Id：" + id);
        boolean rs = examineService.removeById(id);
        return rs ? ResultBean.success() : ResultBean.error("删除失败");
    }


}
